/* xbicommon.h */

#ifndef XBI_Common
#define XBI_Common 1

#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char byte_t;

typedef enum {
    kXBIFileIOError,
    kXBIFileTooSmall,
    kXBIFileWrongFormat,
    kXBINotEnoughMemory
} XBIError;


#define kXBIDVDSectorSize                    2048

#define _XBISecuritySectorSize               kXBIDVDSectorSize
#define _XBIPhysicalFormatInformationSize    kXBIDVDSectorSize
#define _XBIDiskManufacturingInformationSize kXBIDVDSectorSize

#define _XBIMediaIDLength 16

#define DEBUG 1

#if DEBUG
#define XBILog(msg, ...) printf(msg, ## __VA_ARGS__)
#define XBIAssert(condition, msg, ...) do { if (!(condition)) { printf("Assertion failed (%s) : ", #condition); printf(msg, ## __VA_ARGS__); abort();} } while(0)
#else
#define XBILog(msg, ...)
#define XBIAssert(condition, msg, ...)
#endif

int XBIBufferIsEmpty(byte_t * buffer, int size);

uint16_t XBIReadLittleEndianUInt16AtAddress(byte_t * buffer);
uint32_t XBIReadLittleEndianUInt32AtAddress(byte_t * buffer);
int32_t  XBIReadLittleEndianInt32AtAddress(byte_t * buffer);
int64_t  XBIReadLittleEndianInt64AtAddress(byte_t * buffer);
int32_t  XBIReadBigEndianInt32AtAddress(byte_t * buffer);
time_t   XBIWin32FileTimeToUnixTime(int64_t time);

off_t XBIGetFileSize(FILE * file);
byte_t * XBICreateBufferFromFile(FILE * file, size_t * bufferSize);

// Crypto functions

uint32_t XBIComputeCRC32(byte_t * buffer, size_t size);


#endif
